package com.bjx.generator.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjx.common.core.domain.R;
import com.bjx.generator.domain.entity.TableInfoEntity;
import com.bjx.generator.domain.query.TableInfoQuery;
import com.bjx.generator.domain.vo.TableInfoVO;
import com.bjx.generator.service.ITableInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 表信息控制器
 * @author: liushuai
 * @date: 2022/9/11 20:10
 */
@RestController
@Tag(name = "表信息控制器")
@RequestMapping("/table/info")
public class TableInfoController {
    @Autowired
    private ITableInfoService tableInfoService;

    /**
     * 根据表面保存表信息
     * @param tableName
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/9/14
     */
    @GetMapping("insertTableInfo")
    @Operation(summary = "新增数据库表信息")
    public R insertTableInfo(@RequestParam String tableName){
        tableInfoService.insertTableInfo(tableName);
        return R.successMsg("新增表实例成功");
    }
    /**
     * 分页查询表信息
     * @param tableInfoQuery
     * @return: com.bjx.common.core.domain.R<com.baomidou.mybatisplus.core.metadata.IPage>
     * @Author: liushuai
     * @Date: 2022/9/16 13:58
     */
    @GetMapping("listTableInfoPage")
    @Operation(summary = "分页查询表信息")
    public R<IPage<TableInfoEntity>> listTableInfoPage(TableInfoQuery tableInfoQuery){
       IPage<TableInfoEntity> page = tableInfoService.listTableInfoPage(tableInfoQuery);
       return R.success(page);
    }

    /**
     * 查询表信息列表
     * @param tableInfoQuery
     * @return
     */
    @GetMapping("listTableInfo")
    @Operation(summary = "查询表信息列表")
    public R<List<TableInfoEntity>> listTableInfo(TableInfoQuery tableInfoQuery){
        List<TableInfoEntity> list = tableInfoService.listTableInfo(tableInfoQuery);
        return R.success(list);
    }

    /**
     * 根据表id获取表信息
     * @param tableId
     * @return: com.bjx.common.core.domain.R<com.bjx.generator.domain.vo.TableInfoVO>
     * @Author: liushuai
     * @Date: 2022/9/16 14:40
     */
    @GetMapping("selectTableInfoByTableId")
    @Operation(summary = "根据表id查询表信息")
    public R<TableInfoVO> selectTableInfoByTableId(@RequestParam Long tableId){
        TableInfoVO vo = tableInfoService.selectTableInfoByTableId(tableId);
        return R.success(vo);
    }

    /**
     * 根据表id删除表信息
     * @param tableId
     * @return
     */
    @GetMapping("deleteTableInfoByTableId")
    @Operation(summary = "根据表id删除表信息")
    public R deleteTableInfoByTableId(@RequestParam Long tableId){
        tableInfoService.deleteTableInfoByTableId(tableId);
        return R.successMsg("删除成功");
    }

    /**
     * 根据表id修改表信息
     * @param vo
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/9/14
     */
    @PostMapping("updateTableInfoByTableId")
    @Operation(summary = "修改数据库表信息")
    public R updateTableInfoByTableId(@RequestBody TableInfoVO vo) {
        tableInfoService.updateTableInfoByTableId(vo);
        return R.successMsg("修改数据库表信息成功");
    }


}
